package com.lcneves.cookme; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.Window; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ShareActionProvider; import android.widget.Toast; public class RecipeViewer extends Activity { WebView webview; String[] recipe; String name; String url; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.recipe_viewer); Intent intent = getIntent(); recipe = intent.getStringArrayExtra("com.lcneves.cookme.RECIPE"); name = recipe[0]; url = recipe[2]; webview = (WebView) findViewById(R.id.webView); setTitle(name); webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setBuiltInZoomControls(true); final Activity activity = this; webview.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { // Activities and WebViews measure progress with different scales. // The progress meter will automatically disappear when we reach 100% activity.setProgress(progress * 1000); } }); webview.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Toast.makeText(activity, "Loading error: " + description, Toast.LENGTH_LONG).show(); } }); Log.d("com.lcneves.cookme.RecipeViewer", url); webview.loadUrl(url); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.recipe_viewer, menu); // Locate MenuItem with ShareActionProvider MenuItem item = menu.findItem(R.id.menu_item_share); // Fetch and store ShareActionProvider ShareActionProvider mShareActionProvider = (ShareActionProvider) item.getActionProvider(); Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, name+": "+url); sendIntent.setType("text/plain"); mShareActionProvider.setShareIntent(sendIntent); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if(id == android.R.id.home) { Intent intent = new Intent(this, SearchSimple.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(intent); return true; } return super.onOptionsItemSelected(item); } public void clickAboutMenuViewer(MenuItem menu) { MainActivity.AboutDialogFragment aboutDialog = new MainActivity.AboutDialogFragment(); aboutDialog.show(getFragmentManager(), "tag"); } }